//
//  MarketHeadTitleView.m
//  BTCoin
//
//  Created by Robin on 19/03/2018.
//  Copyright © 2018 Robin. All rights reserved.
//

#import "MarketHeadTitleView.h"

@interface MarketHeadTitleView ()
@property (nonatomic,strong) UIView * lineView;
@end


@implementation MarketHeadTitleView

- (instancetype)init {
    self = [super init];
    if (self) {
        UILabel * BTKLabel = [[UILabel alloc] init];
        [BTKLabel setFont:[UIFont systemFontOfSize:17]];
        [BTKLabel setTextColor:COLOR_Bg_White];
        BTKLabel.text = NSLocalizedString(@"行情", nil);
        [BTKLabel setTextAlignment:NSTextAlignmentCenter];
        [self addSubview:BTKLabel];
        [BTKLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(self);
            make.centerY.equalTo(self);
        }];
    }
    
    return self;
}

#pragma mark - event actions
- (void)titleAction:(UIButton *)sender {
    [UIView animateWithDuration:0.3 animations:^{
        [self.lineView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(sender.tag*(self.width/2));
        }];
        if (self.block) {
            self.block(sender.tag);
        }
        [self setNeedsLayout];
        [self layoutIfNeeded];
    } completion:^(BOOL finished) {
        
    }];
}

#pragma mark - public methods
- (void)updateLinePoint:(NSInteger)tag {
    [UIView animateWithDuration:0.3 animations:^{
        [self.lineView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(tag*(self.width/2));
        }];
        [self setNeedsLayout];
        [self layoutIfNeeded];
    } completion:^(BOOL finished) {
        
    }];
}

@end
